<template>
  <div>
    <van-nav-bar @click-left="onClickLeft" title="账号登录" left-arrow>
    </van-nav-bar>
    <van-form @submit="onSubmit">
      <van-field
        v-model="form.username"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="form.password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
    <a href="javascript:;">还没有账号点击去注册</a>
  </div>
</template>

<script>
import { goLogin } from '@/api/login.js'
export default {
  data () {
    return {
      form: {
        username: '',
        password: ''
      }
    }
  },

  created () {},

  methods: {
    async onSubmit () {
      try {
        const res = await goLogin(this.form)
        // console.log(res)
        if (res.status === 200) { this.$router.push('/layout/home') }
      } catch (err) {
        console.log(err)
      }
    },
    onClickLeft () {
      this.$router.back()
    }
  }
}
</script>

<style scoped lang="less"></style>
